package cn.stylefeng.guns.cloud.workflow.modular.controller;

import cn.stylefeng.guns.cloud.libs.scanner.annotation.GetResource;
import cn.stylefeng.guns.cloud.libs.scanner.stereotype.ApiResource;
import cn.stylefeng.guns.cloud.model.web.response.ResponseData;
import cn.stylefeng.guns.cloud.system.api.model.UserInfo;
import cn.stylefeng.guns.cloud.system.api.model.WorkflowRoleInfo;
import cn.stylefeng.guns.cloud.workflow.modular.service.ActBaseService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 工作流通用控制器，用于工作流编辑器获取人员信息
 *
 * @author fengshuonan
 * @Date 2019/10/1 7:27
 */
@RestController
@ApiResource(name = "工作流人员管理", path = "/common")
@Api(tags = "工作流人员管理")
public class CommonController {

    @Autowired
    private ActBaseService actBaseService;

    @GetResource(name = "获取角色列表", path = "/roleList")
    @ApiOperation(value = "获取角色列表")
    public ResponseData roleList() {
        List<WorkflowRoleInfo> roleList = actBaseService.getRoleList();
        return ResponseData.success(roleList);
    }

    @GetResource(name = "获取角色下用户列表（分页）", path = "/userListByRoleId")
    @ApiOperation(value = "获取角色下用户列表（分页）")
    public ResponseData userListByRoleId(@RequestParam("roleId") Long roleId) {
        Page<UserInfo> userPage = actBaseService.getUserListByRoleId(roleId);
        return ResponseData.success(userPage);
    }
}
